package object04;

import java.util.Objects;

public class Person {
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Person person)) return false;
        return age == person.age && name.equals(person.name);
    }
    

    /*@Override
    public boolean equals(Object obj) {
        // Object obj = a = new Animal() 父类引用指向子类对象，多态

        if(this==obj){         // this = p2  obj = p2 , p2==p2  true
            return true;       // 直接return true 如果是同一个人就不走下面的比较姓名和年龄
        }                     // 提高代码效率

        if(!(obj instanceof Person)){ // 如果obj引用指向的对象不是Person类的对象
            return false;             // 那么我们就返回false
        }
        Person p = (Person)obj;

        return this.age == p.age && this.name.equals(p.name);
    }*/
}

